//
//  NewsDetailTwoViewController.m
//  网易新闻
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 马文强. All rights reserved.
//

#import "NewsDetailTwoViewController.h"
#import "netWorkHandle.h"
#import "UIImageView+WebCache.h"
@interface NewsDetailTwoViewController ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *threeArray;

@end

@implementation NewsDetailTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    [self loadscrollVeiw];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    [self dismissViewControllerAnimated:YES completion:nil];

}
- (NSMutableArray *)threeArray
{
    if (_threeArray == nil) {
        _threeArray = [NSMutableArray array];
    }
    return _threeArray;
}
#pragma mark ---- 轮播图 ---
- (void)loadscrollVeiw{
    //初始化UIScrollView alloc
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 160, self.view.frame.size.width, 300)];
    //是否整平翻动
    self.scrollView.pagingEnabled = YES;
    //边缘弹动效果
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [NetWorkHandle getDataWithURLString:_threeImage compare:^(id object) {
        
        NSLog(@"%@",_threeImage);
        NSDictionary *dic = object;
        NSArray *arr = [dic objectForKey:@"photos"];
        _threeArray = [NSMutableArray array];
        for (NSDictionary *dictionary in arr) {
            
            [_threeArray addObject:dictionary[@"imgurl"]];
            
        }
        for (int i = 0; i < _threeArray.count; i ++) {
            
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, 300)];
            [imageView sd_setImageWithURL:[NSURL URLWithString:self.threeArray[i]]];
            NSLog(@"%@",self.threeArray[i]);
            
            [_scrollView addSubview:imageView];
            
        }
        
        //确保数据拿到之后 才去设置UIScrollveiw的contentsize
        self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * _threeArray.count, 0);
        
    }];
    
    [self.view addSubview:_scrollView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
 
}



@end
